{include file="public/header" /}
<style>
    /*缩略图高度*/
    .layui-table-cell {height: 36px;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">

                        <div class="layui-input-inline" style="margin-top: 5px">
                            <select name="recycle_brand_id" lay-search="" class="layui-input search" id="brand_id" lay-filter="brand_id">
                                <option value="">---- 请选择品牌 ----</option>
                                {foreach name="brand" item="vo"}
                                <option value="{$vo.brand_id}" >{$vo.brand_name}</option>
                                {/foreach}
                            </select>
                        </div>

                        <div class="layui-input-inline" style="margin-top: 5px">
                            <select name="recycle_models_id" lay-search="" class="layui-input search" id="models_id" lay-filter="models_id">
                                <option value="">---- 请选择型号 ----</option>
                            </select>
                        </div>

                        <div class="layui-col-md6 layui-input-inline" style="margin-top: 5px">
                            <input type="text" class="layui-input search" name="recycle_name" placeholder="名称"/>
                        </div>

                        <div class="layui-input-inline layui-form" style="margin-top: 5px">
                            <select name="recycle_status" class="layui-input">
                                <option value="" >不限状态</option>
                                <option value="1">上架中</option>
                                <option value="2">已下架</option>
                            </select>
                        </div>

                        <div class="layui-input-inline" style="margin-top: 5px">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>

                <div class="col-sm-12">
                    <div class="input-group" >
                    </div>
                </div>
            </div>
            <div class="row">

                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.href('{:url('recycleAdd')}');">
                            <i class="fa fa-plus"></i> 添加故障
                        </button>
                        <button  class="btn btn-danger m-l-xs" href="javascript:;" data-toggle="dropdown">
                            <i class="fa fa-wrench"></i> 批量操作 <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu layui-anim layui-anim-upbit" role="menu">
                            <li><a  href="javascript:;" class="layuiBtn" data-type="copyAll"><i class="fa fa-external-link"></i> 批量复制</a></li>
                        </ul>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>

                    <!--操作模板-->
                    <script type="text/html" id="recycle_status">
                        {{# if(d.recycle_status == 1){ }}
                        上架中
                        {{# } }}
                        {{# if(d.recycle_status == 2){ }}
                        已下架
                        {{# } }}
                    </script>

                    <script type="text/html" id="recycle_is_more">
                        {{# if(d.recycle_is_more == 1){ }}
                        是
                        {{# } }}
                        {{# if(d.recycle_is_more == 2){ }}
                        否
                        {{# } }}
                    </script>

                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.href('{:url('recycleEdit')}?recycle_id={{d.recycle_id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑"><i class="fa fa-pencil">编辑</i></a>
                        {{# if(d.recycle_status == 1) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.recycle_id}}','{:url('recycleDown')}', '确定下架？')" class="btn btn-warning btn-xs m-r-xs" title="下架"><i class="fa fa-arrow-down">下架</i></a>
                        {{# } }}
                        {{# if(d.recycle_status == 2) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.recycle_id}}','{:url('recycleUp')}', '确定上架？')" class="btn btn-info btn-xs m-r-xs" title="上架"><i class="fa fa-arrow-up">上架</i></a>
                        {{# } }}
                        <!--<a href="javascript:;" onclick="wk.layer_show('故障小项列表', '{:url('infoList')}?recycle_id={{d.recycle_id}}')" class="btn btn-warning btn-xs m-r-xs" title="故障小项">故障小项</a>-->
                        <a href="javascript:;" onclick="wk.confirm('{{d.recycle_id}}','{:url('recycleDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o">删除</i></a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Recycle/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
//            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 300]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
//                , {field: 'user_id', width: 60, title: 'ID', align: 'center'}
                , {field: 'recycle_name', width: 140, title: '名称', align: 'center'}
                , {field: 'brand_name', width: '', title: '品牌', align: 'center'}
                , {field: 'models_name', width: '', title: '型号', align: 'center'}
                , {field: 'recycle_sort', width: 130, title: '排序（可编辑）', align: 'center', edit: 'test'}
                , {field: 'recycle_status', width: 90, title: '状态', align: 'center',toolbar: '#recycle_status'}
                , {field: 'recycle_is_more', width: 120, title: '是否功能选项', align: 'center',toolbar: '#recycle_is_more'}
                , {fixed: 'right', width:280, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
            }
        });
        //批量操作
        var $ = layui.$, active = {
            //批量复制
            copyAll:function () {
                var ids = getIds();
                if(ids == ''){
                    layer.msg('请选择需要复制的回收故障', {icon:2, time:2000, shade: 0.1});
                    return;
                }
                wk.layer_show('请选择', '{:url('admin/recycle/copyRecycle')}?recycle_id='+ids);
            }
        };
        //监听单元格编辑---排序
        table.on('edit(demo)', function(obj){
            var value = obj.value //得到修改后的值
                    ,data = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
            wk.change(data.recycle_id,"{:url('updateSort')}",field,value);
        });

        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['recycle_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>